package com.ruoyi.trainingManagement.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.trainingManagement.domain.TrainingCredit;
import com.ruoyi.trainingManagement.service.ITrainingCreditService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培养管理学分Controller
 * 
 * @author chenxl
 * @date 2025-09-09
 */
@RestController
@RequestMapping("/trainingManagement/credit")
public class TrainingCreditController extends BaseController
{
    @Autowired
    private ITrainingCreditService trainingCreditService;

    /**
     * 查询培养管理学分列表
     */
//    @PreAuthorize("@ss.hasPermi('trainingManagement:credit:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingCredit trainingCredit)
    {
        startPage();
        List<TrainingCredit> list = trainingCreditService.selectTrainingCreditList(trainingCredit);
        return getDataTable(list);
    }

    /**
     * 导出培养管理学分列表
     */
    //@PreAuthorize("@ss.hasPermi('trainingManagement:credit:export')")
    @Log(title = "培养管理学分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingCredit trainingCredit)
    {
        List<TrainingCredit> list = trainingCreditService.selectTrainingCreditList(trainingCredit);
        ExcelUtil<TrainingCredit> util = new ExcelUtil<TrainingCredit>(TrainingCredit.class);
        util.exportExcel(response, list, "培养管理学分数据");
    }

    /**
     * 获取培养管理学分详细信息
     */
    //@PreAuthorize("@ss.hasPermi('trainingManagement:credit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        System.out.println("获取到的查询学分表的参数"+ id);
        System.out.println("获取到的查询学分表"+ trainingCreditService.selectTrainingCreditById(id));
        return success(trainingCreditService.selectTrainingCreditById(id));

    }

    /**
     * 新增培养管理学分
     */
    //@PreAuthorize("@ss.hasPermi('trainingManagement:credit:add')")
    @Log(title = "培养管理学分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingCredit trainingCredit)
    {
        return toAjax(trainingCreditService.insertTrainingCredit(trainingCredit));
    }

    /**
     * 修改培养管理学分
     */
    //@PreAuthorize("@ss.hasPermi('trainingManagement:credit:edit')")
    @Log(title = "培养管理学分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingCredit trainingCredit)
    {
        return toAjax(trainingCreditService.updateTrainingCredit(trainingCredit));
    }

    /**
     * 删除培养管理学分
     */
    //@PreAuthorize("@ss.hasPermi('trainingManagement:credit:remove')")
    @Log(title = "培养管理学分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(trainingCreditService.deleteTrainingCreditByIds(ids));
    }
}
